
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;



/*
 * GiaoDienClient.java
 *
 * Created on Nov 2, 2010, 3:22:41 PM
 */



/**
 *
 * @author GTVT
 */
public class GiaoDienClient extends javax.swing.JFrame {
    private boolean allowGV=true;
    private boolean allowNT=true;
    
    /** Creates new form GiaoDienClient */
    public GiaoDienClient() {
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(GiaoDienClient.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(GiaoDienClient.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(GiaoDienClient.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(GiaoDienClient.class.getName()).log(Level.SEVERE, null, ex);
        }

        initComponents();

    
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
   // @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        cbTenNT = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        cbNgay = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        cmdCompareTG = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cbKhuVuc = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel4 = new javax.swing.JLabel();
        cbThoiGian = new javax.swing.JComboBox();
        cmdCompare = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        txtIP = new javax.swing.JTextField();
        txtPort = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        cmdOk = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new java.awt.GridLayout(1, 0));

        jPanel2.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                jPanel2ComponentShown(evt);
            }
        });

        jScrollPane2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tỉ Giá Ngoại Tệ Nguồn NH-Ngoại Thương", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Mã", "Tên Ngoại tệ", "Mua tiền mặt", "Mua chuyển khoản", "Bán"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jTable2);

        cbTenNT.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbTenNTItemStateChanged(evt);
            }
        });
        cbTenNT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbTenNTActionPerformed(evt);
            }
        });
        cbTenNT.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                cbTenNTPropertyChange(evt);
            }
        });
        cbTenNT.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cbTenNTKeyTyped(evt);
            }
        });

        jLabel2.setText("Tên ngoại tệ");

        cbNgay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbNgayActionPerformed(evt);
            }
        });

        jLabel3.setText("Ngày");

        cmdCompareTG.setText("Compare");
        cmdCompareTG.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdCompareTGActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 573, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cbTenNT, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(35, 35, 35)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbNgay, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                        .addComponent(cmdCompareTG, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(34, Short.MAX_VALUE))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel2)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                        .addComponent(cbNgay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                        .addComponent(cmdCompareTG))
                    .addComponent(cbTenNT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32))
        );

        jTabbedPane1.addTab("Giá DoLa", jPanel2);

        jPanel1.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                jPanel1ComponentShown(evt);
            }
        });

        jLabel1.setText("Khu vực");

        cbKhuVuc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbKhuVucActionPerformed(evt);
            }
        });

        jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "NGUỒN CTY SJC VIỆT NAM", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Khu Vực", "Loại Vàng", "Giá Bán", "Giá Mua"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jLabel4.setText("Thời Gian");

        cbThoiGian.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbThoiGianActionPerformed(evt);
            }
        });

        cmdCompare.setText("Compare");
        cmdCompare.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdCompareActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 564, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cbKhuVuc, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cbThoiGian, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(cmdCompare, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(37, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(cmdCompare)
                    .addComponent(jLabel1)
                    .addComponent(cbKhuVuc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbThoiGian, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Giá Vàng", jPanel1);

        jPanel3.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                jPanel3ComponentShown(evt);
            }
        });

        jLabel5.setText("IP Server");

        txtIP.setText("127.0.0.1");
        txtIP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIPActionPerformed(evt);
            }
        });
        txtIP.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                txtIPInputMethodTextChanged(evt);
            }
        });

        txtPort.setText("2812");
        txtPort.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPortActionPerformed(evt);
            }
        });
        txtPort.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                txtPortInputMethodTextChanged(evt);
            }
        });

        jLabel6.setText("Port");

        cmdOk.setText("Apply");
        cmdOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdOkActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(197, 197, 197)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(cmdOk, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtPort)
                            .addComponent(txtIP, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(246, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(103, 103, 103)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(cmdOk)
                .addContainerGap(135, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Cấu Hình", jPanel3);

        getContentPane().add(jTabbedPane1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cbKhuVucActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbKhuVucActionPerformed

        if(this.cbKhuVuc.getItemCount()<1)
            return;
        if(allowGV==true)
            yeucauGiaVang(this.cbKhuVuc.getSelectedItem().toString());
    }//GEN-LAST:event_cbKhuVucActionPerformed

    private void cbTenNTKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cbTenNTKeyTyped

}//GEN-LAST:event_cbTenNTKeyTyped

    private void cbTenNTPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_cbTenNTPropertyChange

}//GEN-LAST:event_cbTenNTPropertyChange

    private void cbTenNTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTenNTActionPerformed
        if(cbNgay.getItemCount()<1 || cbTenNT.getItemCount()<1)
            return;
      //  String tmp=cbNgay.getSelectedItem().toString()+cbTenNT.getSelectedItem().toString();
        if(allowNT==true)
        {
            getNgoaiTe(cbNgay.getSelectedItem().toString(),cbTenNT.getSelectedItem().toString());
                  //  curItem=tmp;
        }

}//GEN-LAST:event_cbTenNTActionPerformed

    private void cbTenNTItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbTenNTItemStateChanged

}//GEN-LAST:event_cbTenNTItemStateChanged

    private void jPanel1ComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jPanel1ComponentShown

        this.prepareItem();
    }//GEN-LAST:event_jPanel1ComponentShown

    private void cbThoiGianActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbThoiGianActionPerformed
        // TODO add your handling code here:
        if(allowGV)
        {
            cbKhuVuc.removeAllItems();
            Object []obj=this.getKhuVuc();
            for(int i=0;i<obj.length;++i)
                cbKhuVuc.addItem(obj[i]);
            cbKhuVuc.addItem("ALL");
        }
    }//GEN-LAST:event_cbThoiGianActionPerformed

    private void cmdCompareActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdCompareActionPerformed
        JDSelect select=new JDSelect(this,true);
        ArrayList lstNgay=new ArrayList();
        ArrayList lstKhuVuc=new ArrayList();
        int i;
        for(i=0;i<cbThoiGian.getItemCount();++i)
            lstNgay.add(cbThoiGian.getItemAt(i));
        for(i=0;i<cbKhuVuc.getItemCount();++i)
            lstKhuVuc.add(cbKhuVuc.getItemAt(i));
        select.setData(lstNgay, lstKhuVuc,Constants.GIAVANG);
        select.setLocationRelativeTo(null);
        select.setTitle("Lua Chon");
        select.setVisible(true);
    }//GEN-LAST:event_cmdCompareActionPerformed

    private void jPanel2ComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jPanel2ComponentShown
        // TODO add your handling code here:
        try{
            this.prepareItemNT();
        }
        catch(Exception ex)
        {
            System.out.println(ex.toString());
        }
    }//GEN-LAST:event_jPanel2ComponentShown

    private void cbNgayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbNgayActionPerformed
        // TODO add your handling code here:
        try{
            if(allowNT)
            {
                Object[] obj = getTenNT();
                if(obj.length==0) return;
                cbTenNT.removeAllItems();
                for(int i=0;i<obj.length;++i)
                    cbTenNT.addItem(obj[i]);
                cbTenNT.addItem("ALL");
            }
        }catch(Exception ex)
        {

        }
      
    }//GEN-LAST:event_cbNgayActionPerformed

    private void cmdCompareTGActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdCompareTGActionPerformed
        JDSelect select=new JDSelect(this,true);
        ArrayList lstNgay=new ArrayList();
        ArrayList lstTenNT=new ArrayList();
        int i;
        for(i=0;i<cbNgay.getItemCount();++i)
            lstNgay.add(cbNgay.getItemAt(i));
        for(i=0;i<cbTenNT.getItemCount();++i)
            lstTenNT.add(cbTenNT.getItemAt(i));
        select.setData(lstNgay, lstTenNT,Constants.TIGIA);
        select.setLocationRelativeTo(null);
        select.setTitle("Lua Chon");
        select.setVisible(true);
    }//GEN-LAST:event_cmdCompareTGActionPerformed

    private void txtIPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtIPActionPerformed
       cmdOk.setEnabled(true);
}//GEN-LAST:event_txtIPActionPerformed

    private void cmdOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdOkActionPerformed
        try{
            UDPCC.ipS=txtIP.getText();
            UDPCC.portS=Integer.parseInt(txtPort.getText());
            cmdOk.setEnabled(false);
        }catch(Exception e) {

        }
    }//GEN-LAST:event_cmdOkActionPerformed

    private void jPanel3ComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jPanel3ComponentShown
        txtIP.setText(UDPCC.ipS);
        txtPort.setText(Integer.toString(UDPCC.portS));
    }//GEN-LAST:event_jPanel3ComponentShown

    private void txtPortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPortActionPerformed

    }//GEN-LAST:event_txtPortActionPerformed

    private void txtIPInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_txtIPInputMethodTextChanged
        cmdOk.setEnabled(true);
    }//GEN-LAST:event_txtIPInputMethodTextChanged

    private void txtPortInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_txtPortInputMethodTextChanged
        cmdOk.setEnabled(true);
    }//GEN-LAST:event_txtPortInputMethodTextChanged

    private int getNgoaiTe(String thoigian,String tenNT)
    {
        StringBuilder s = new StringBuilder();
        s.append(Constants.TIGIA+",");
        s.append(thoigian+",");
        s.append(tenNT);


        UDPCC thucThi = new UDPCC();
        try {
            ArrayList a = thucThi.ketNoi(s.toString());
            Object[][] obj = new Object [a.size()/4][4];
            for(int i=0;i<a.size()/4;++i)
                for(int j=0;j<4;++j)
                {
                    System.out.println("Dang Nhan Du Lieu");
                    obj[i][j]= a.get(i*4+j);
                }

            jTable2.setModel(new javax.swing.table.DefaultTableModel(
              obj, new String [] {"Tên Ngoại tệ", "Mua tiền mặt", "Mua chuyển khoản", "Bán"})
            {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };


                @Override
            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jTable2);


        } catch (Exception ex) {
            return 1;

        }
        return 0;
    }
    private Object[] getKhuVuc()
    {
        UDPCC thucThi = new UDPCC();
        StringBuilder s = new StringBuilder();
        s.append(Constants.KHUVUCGV+",");
        s.append(cbThoiGian.getSelectedItem());
        try {
            ArrayList a = thucThi.ketNoi(s.toString());
            Object []obj=new Object[a.size()];
            for(int i=0;i<a.size();++i)
                obj[i]=a.get(i);
            return obj;
        } catch (Exception ex) {
            Logger.getLogger(GiaoDienClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    private Object[] getThoiGianGV()
    {
        UDPCC thucThi = new UDPCC();
        StringBuilder s = new StringBuilder();
        s.append(Constants.THOIGIANGV);
        try {
            ArrayList a = thucThi.ketNoi(s.toString());
            Object []obj=new Object[a.size()];
            for(int i=0;i<a.size();++i)
                obj[i]=a.get(i);
            return obj;
        } catch (Exception ex) {
            Logger.getLogger(GiaoDienClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    private Object[] getTenNT() throws Exception
    {
        UDPCC udp = new UDPCC();
        StringBuilder s = new StringBuilder();
        s.append(Constants.TENTG+",");
        s.append(cbNgay.getSelectedItem());
        ArrayList a = udp.ketNoi(s.toString());
        Object []obj=new Object[a.size()];
        for(int i=0;i<a.size();++i)
            obj[i]=a.get(i);
        return obj;
    }

    private Object[] getThoiGianTG() throws Exception
    {
        UDPCC udp = new UDPCC();
        StringBuilder s = new StringBuilder();
        s.append(Constants.THOIGIANTG);
        ArrayList a = udp.ketNoi(s.toString());
        Object []obj = new Object[a.size()];
        for(int i=0;i<a.size();++i)
            obj[i]=a.get(i);
        return obj;

    }

    private void yeucauGiaVang(String khuvuc)
    {
        UDPCC thucThi = new UDPCC();
        StringBuilder s = new StringBuilder();
        s.append(Constants.GIAVANG+",");
        s.append(khuvuc+",");
        s.append(cbThoiGian.getSelectedItem());
      //  System.out.println("Gui Di Yeu Cau:"+s);
        try {
            ArrayList a = thucThi.ketNoi(s.toString());
          //  System.out.println("Gui yeu Cau:"+s.toString());
            Object[][] obj = new Object [a.size()/4][4];
            for(int i=0;i<a.size()/4;++i)
                for(int j=0;j<4;++j)             
                    obj[i][j]= a.get(i*4+j);
            jTable1.setModel(new javax.swing.table.DefaultTableModel(
                obj,
            new String [] {
                "Khu Vực", "Loại Vàng", "Giá Bán", "Giá Mua"
            }
        ));
        jScrollPane1.setViewportView(jTable1);


        } catch (Exception ex) {
            Logger.getLogger(GiaoDienClient.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    //
    //Do du lieu gia vang ve khu vuc va thoi gian vao cac combobox
    //
    private void prepareItem()
    {
        Object []obj;
        int i;
        //Do Cac Khoang Thoi Gian Vao Combobox
        allowGV=false;
        cbThoiGian.removeAllItems();
        obj=this.getThoiGianGV();
        for(i=0;i<obj.length;++i)
            cbThoiGian.addItem(obj[i]);
        allowGV=true;

        cbKhuVuc.removeAllItems();
        obj=this.getKhuVuc();
        for(i=0;i<obj.length;++i)
            cbKhuVuc.addItem(obj[i]);
        cbKhuVuc.addItem("ALL");
    }
    private void prepareItemNT() throws Exception
    {
        Object []obj;
        int i;

        //Do Cac Khoang Thoi Gian Vao Combobox
        allowNT=false;
        cbNgay.removeAllItems();
        obj=this.getThoiGianTG();
        for(i=0;i<obj.length;++i)
            cbNgay.addItem(obj[i]);


        cbTenNT.removeAllItems();
        allowNT=true;
        obj=this.getTenNT();
        for(i=0;i<obj.length;++i)
            cbTenNT.addItem(obj[i]);
       
        cbTenNT.addItem("ALL");
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                 GiaoDienClient frm=new GiaoDienClient();
                 frm.setLocationRelativeTo(null);
                 frm.setVisible(true);

            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbKhuVuc;
    private javax.swing.JComboBox cbNgay;
    private javax.swing.JComboBox cbTenNT;
    private javax.swing.JComboBox cbThoiGian;
    private javax.swing.JButton cmdCompare;
    private javax.swing.JButton cmdCompareTG;
    private javax.swing.JButton cmdOk;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTextField txtIP;
    private javax.swing.JTextField txtPort;
    // End of variables declaration//GEN-END:variables

}
